package com.bw.zg3park2212.order

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.bw.base.entity.OrderAddParam
import com.bw.base.entity.OrderEntityItem
import com.bw.base.mvvm.BaseActivity
import com.bw.zg3park2212.databinding.ActivityOrderUpBinding
import com.bw.zg3park2212.order.OrderViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/OrderUpActivity")
class OrderUpActivity : BaseActivity<ActivityOrderUpBinding,OrderViewModel>() {
    @Autowired
    lateinit var orderup:OrderEntityItem
    override fun intitView() {
        ARouter.getInstance().inject(this)
        viewmodel.getorderxing(orderup.id)
        binding.submit.setOnClickListener {
            var orderAddParam=OrderAddParam()
            orderAddParam.inspector=binding.inspector.text.toString()
            orderAddParam.address=binding.address.text.toString()
            orderAddParam.appointmentTime=binding.appointmentTime1.text.toString()
            orderAddParam.content=binding.content.text.toString()
            orderAddParam.orderType=binding.orderType.text.toString()
            if (binding.btnStatus1.isChecked){
                orderAddParam.status="新建"
            }else if (binding.btnStatus2.isChecked){
                orderAddParam.status="进行中"
            }else if (binding.btnStatus3.isChecked){
                orderAddParam.status="已完成"
            }
            viewmodel.getorderup(orderup.id,orderAddParam)
        }
    }

    override fun intitData() {
        viewmodel.orderxingSuccse.observe(this){
            binding.inspector.setText(it.inspector)
            binding.address.setText(it.address)
            binding.appointmentTime1.setText(it.appointmentTime)
            binding.appointmentTime2.setText(it.appointmentTime)
            binding.content.setText(it.content)
            binding.orderType.setText(it.orderType)
            if (it.status=="新建"){
                binding.btnStatus1.isChecked=true
            }else if (it.status=="进行中"){
                binding.btnStatus2.isChecked=true
            }else if (it.status=="已完成"){
                binding.btnStatus3.isChecked=true
            }
        }
        viewmodel.orderupSuccse.observe(this){
            ToastUtils.showLong("修改成功")
            finish()
        }
    }

}